package com.kk.factory.simplefactory;

import java.util.Scanner;

/**
 * @author 王志强
 * @date 2021-12-10
 */
public class OrderPizzaPlus {


    public OrderPizzaPlus(SimpleFactory simpleFactory) {
        setFactory(simpleFactory);
    }

    public void setFactory(SimpleFactory simpleFactory) {


        while (true) {

            //拿到工厂创建的对象
            String type = "";
            type = getType();
            AbstractPizza pizza = simpleFactory.createPizza(type);

            if (pizza == null) {
                System.out.println("无此pizza，订购失败！");
                break;
            } else {
                pizza.prepare();
            }
        }

    }

    /**
     * 拿到用户输入的 pizza 类型
     */
    private String getType() {
        Scanner scanner = new Scanner(System.in);
        return scanner.nextLine();
    }
}
